home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Utilities / Programming / MT2Trivial 2.1.3 / MT2Trivial 2.1.3 ƒ / MT2Trivial Templates ƒ / MainLoop.p.Trivial < prev    next >
Encoding:
Text File  |  1996-07-28  |  3.1 KB  |  137 lines  |  [TEXT/MPS ]

  1.  
  2. {%%DOC: MainLoop.p.Trivial -- begin}
  3.  
  4.   PROCEDURE DoOSEvent(event: EventRecord; VAR cursorRgn: RgnHandle);
  5.   {Handling operating-system events}
  6.  
  7.     VAR
  8.       window: windowPtr;
  9.       activate: boolean;
  10.  
  11.     BEGIN
  12.       window:=FrontWindow;
  13.       CASE BSR(event.message,24) OF
  14.        mouseMovedMessage:
  15.        
  16.                {%% >> Adjust cursor <<}; 
  17.                 
  18.         suspendResumeMessage:
  19.           BEGIN
  20.             activate:=(BAnd(event.message,resumeFlag)<>0);
  21.             
  22.            {%% >> activate appl. window <<};
  23.            
  24.           END;
  25.         OTHERWISE;
  26.       END;
  27.     END; {DoOSEvent}
  28.  
  29. PROCEDURE DoMouseDown (event: EventRecord; var quit : Boolean);
  30.     VAR
  31.      part         : integer;
  32.      aWindow     : WindowPtr;
  33.      
  34.     BEGIN
  35.       part:=FindWindow(event.where,aWindow);
  36.       CASE part OF
  37.         InSysWindow:     SystemClick(event,aWindow);
  38. %IF.TRIVIAL.RES MBAR                
  39.         inMenuBar:      DoMenuCommand(event,quit);
  40. %END.TRIVIAL 
  41.         inDrag:         {%% >> <<};
  42.         inGoAway:         {%% >> <<};
  43.         inGrow:          {%% >> <<};
  44.         inZoomIn, 
  45.         inZoomOut:         {%% >> handle mouse down in zoombox region <<};
  46.         inContent:        {%% >> <<};
  47.       END; {case part of}
  48.     END; {DoMouseDown}
  49.  
  50.   PROCEDURE MainLoop;
  51.  
  52.     CONST
  53.       kReturnKey = $0D;
  54.       kEnterKey = $03;
  55.       kEscKey = 27;
  56.       
  57.  
  58.     VAR
  59.       key: Char;
  60.       quit,gotEvent,activate : Boolean;
  61.       event: EventRecord;
  62.       cursorRgn: RgnHandle;
  63.  
  64.     BEGIN
  65.       cursorRgn:=NewRgn;
  66.       quit:=false;
  67.       REPEAT
  68.         gotEvent:=WaitNextEvent(everyEvent,event,15,cursorRgn);
  69.         IF gotEvent
  70.           THEN
  71.             CASE event.what OF
  72.               osEvt: DoOSEvent(event,cursorRgn);
  73.               activateEvt: 
  74.                 BEGIN
  75.                   activate:=BAnd(event.modifiers,activeFlag)<>0;
  76.                           {%% >> <<}
  77.                 END;
  78.               updateEvt:     {%% >> <<};
  79.               mouseUp:         {%% >> <<};
  80.  
  81.               mouseDown: DoMouseDown (event,quit);
  82.  
  83.               keyDown,autoKey:
  84.                 BEGIN
  85.                   key:=chr(BAnd(event.message,charCodeMask));
  86.                   IF (BAnd(event.modifiers,cmdKey)<>0)
  87.                     THEN {command key down}
  88.                      {%% >> <<}
  89.                     ELSE IF key IN [chr(kReturnKey),chr(kEnterKey)]
  90.                       THEN {return or enter keys were pressed}
  91.                          {%% >> <<}
  92.                       ELSE IF (key=chr(kEscKey))
  93.                         THEN {esc key was pressed}
  94.                           BEGIN
  95.                            {%% >> <<}
  96.                           END
  97.                          ELSE 
  98.                           {%% >> <<};
  99.                  END;
  100.               diskEvt:              {%% >> <<};
  101.               nullEvent:         {%% >> <<};
  102.             END; {case}
  103.       UNTIL quit;
  104.       DisposeRgn(cursorRgn);
  105.     END; {MainLoop}
  106.  
  107.   PROCEDURE Init;
  108.     BEGIN
  109.       MaxApplZone;
  110.       MoreMasters;
  111.       MoreMasters;
  112.       MoreMasters;
  113.       MoreMasters;
  114.       MoreMasters;
  115.       MoreMasters;
  116.       
  117.       InitGraf(@thePort);
  118.       InitFonts;                    
  119.       InitWindows;
  120.       InitMenus;
  121.       TEInit;                        
  122.        InitDialogs(NIL);
  123.       InitCursor;                     
  124. %IF.TRIVIAL.RES MBAR
  125.        DoMakeMenus;
  126. %END.TRIVIAL
  127.   
  128.       {%% >> add another initialization here <<}
  129.     END; {Init}
  130.     
  131. BEGIN {program body}
  132.  Init;
  133.  MainLoop;
  134. END.
  135. {%%DOC: MainLoop.p.Trivial -- eof}
  136.  
  137.